package array;

public class leetCode4_findMedianSortedArrays {

    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
       int n = nums1.length;
       int m = nums2.length;

       int[] tmp = new int[n + m];
       int i = 0;
       int j = 0;
       int t = 0;

       while (i < n && j < m){
           if(nums1[i]<nums2[j]){
               tmp[t++] = nums1[i++];
           }else{
               tmp[t++] = nums2[j++];
           }
       }
       while (i < n){
           tmp[t++] = nums1[i++];
       }
       while (j < m){
           tmp[t++] = nums2[j++];
       }
       double result = -1;
       if(tmp.length % 2 == 0){
           result = (double)(tmp[tmp.length/2 - 1] + tmp[tmp.length/2])/2;
       }else{
           result = tmp[tmp.length/2];
       }

       return result;


    }

}
